| Total Complexity | 3 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 7 | |||
| 8 | @CommandHandler(RemoveUserCommand) |
||
| 9 | export class RemoveUserCommandHandler { |
||
| 10 | constructor( |
||
| 11 | @Inject('IUserRepository') |
||
| 12 | private readonly userRepository: IUserRepository, |
||
| 13 | ) {} |
||
| 14 | |||
| 15 | public async execute({ id, currentUserId }: RemoveUserCommand): Promise<void> { |
||
| 16 | if (id === currentUserId) { |
||
| 17 | throw new CantRemoveYourselfException(); |
||
| 18 | } |
||
| 19 | |||
| 20 | const user = await this.userRepository.findOneById(id); |
||
| 21 | |||
| 22 | if (!user) { |
||
| 23 | throw new UserNotFoundException(); |
||
| 24 | } |
||
| 25 | |||
| 26 | await this.userRepository.remove(user); |
||
| 27 | } |
||
| 29 |